package com.example.performance.jol.official;

import org.openjdk.jol.info.ClassLayout;
import org.openjdk.jol.vm.VM;

/**
 * @author Aleksey Shipilev
 */
@SuppressWarnings({"java:S101", "java:S106"})
public class JOLSample_02_Alignment {

    /*
     * This is the more advanced field layout example.
     *
     * Because the underlying hardware platform often requires aligned accesses
     * to maintain the performance and correctness,
     * it is expected the fields are aligned by their size.
     * For booleans it does not mean anything, but for longs it's different.
     * In this example, we can see the long field is indeed aligned for 8 bytes,
     * sometimes making the gap after the object header.
     */
    public static void main(String[] args) {
        System.out.println(VM.current().details());
        System.out.println(ClassLayout.parseClass(A.class).toPrintable());
    }

    @SuppressWarnings("unused")
    static class A {
        long f;
    }

}